import { ApiProperty } from '@nestjs/swagger';

export class ResultData {
  // private code: number  ;
  constructor(code = 200, msg?: string, data?: any) {
    this.code = code;
    this.msg = msg || 'ok';
    this.data = data || null;
  }
  @ApiProperty({ description: '错误码' })
  code: number;
  @ApiProperty({ description: '信息' })
  msg?: string;
  @ApiProperty({ description: '数据' })
  data?: any;
  static ok(data?: any, msg?: string): ResultData {
    return new ResultData(null, msg, data);
  }
  static error(code: number, msg?: string, data?: any): ResultData {
    return new ResultData(code || 500, msg || 'fail', data);
  }
}
